package com.woniu.util;

import lombok.Data;

@Data
public class JsonResult<T> {
    private Integer code;
    private String message;
    private T data;

    public JsonResult() {

    }

    public JsonResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> JsonResult<T> build(Integer code, String message, T data) {
        return new JsonResult<T>(code, message, data);
    }

    public static <T> JsonResult<T> ok(Integer code, T data) {
        return new JsonResult<T>(200, "请求成功", data);
    }

    public static <T> JsonResult<T> error(T data) {
        return new JsonResult<T>(500, "请求失败", data);
    }
}